package com.example.apistroage;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

/**
 * Author by Administrator,
 * Date on 2022年7月28日.
 */
public class SDCardHolder extends ConstraintLayout {

    private TextView tvPath;
    private TextView tvTotal;
    private TextView tvAvailable;
    private TextView tvfreeBlock;
    private TextView tvMounted;


    public SDCardHolder(@NonNull Context context) {
        super(context);
        init();
    }

    public SDCardHolder(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public SDCardHolder(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_sd_info, this, true);
        tvPath = findViewById(R.id.tv_storage_path);
        tvTotal = findViewById(R.id.tv_storage_total);
        tvAvailable = findViewById(R.id.tv_storage_available);
        tvfreeBlock = findViewById(R.id.tv_storage_free);
        tvMounted = findViewById(R.id.tv_mount_status);
    }

    public void setData(SDData data) {
        if (data != null) {
            tvAvailable.setText("可用空间 : " + data.available);
            tvTotal.setText("总共空间 : " + data.total);
            tvPath.setText("存储路径 : " + data.path);
            tvMounted.setText(data.mounted);
            tvMounted.setTextColor(data.amountedColor);
            tvfreeBlock.setVisibility(GONE);
//            tvfreeBlock.setText("空间 : "+data.freeBlock);
        }

    }


    @Override
    public View getRootView() {
        return super.getRootView();
    }
}
